#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[105];
int n,k;
int solve(int x) {
	int w=a[x],l=x-1,r=x+1,ans=0;
	while(1) {
		if(l==0 && r==n+1) break;
		if(l>0 && r<=n) {
			if(a[r]<=a[l] && a[r]>w) {
				w=a[r]; r++; ans+=k+1;
			}
			else if(a[r]<=a[l] && a[r]<=w) {
				r++; ans++;
			}
			else if(a[r]>a[l] && a[l]>w) {
				w=a[l]; l--; ans+=k+1;
			}
			else if(a[r]>a[l] && a[l]<=w) {
				l--; ans++;
			}
		} 
		if(l==0 && r<=n) {
			if(a[r]>w) {
				w=a[r]; r++; ans+=k+1;
			} else {
				r++,ans++;
			}
		}
		if(r==n+1 && l>0) {
			if(a[l]>w) {
				w=a[l]; l--; ans+=k+1;
			} else {
				l--,ans++;
			}
		}
	}
	return ans;
}
signed main() {
	freopen("summer.in","r",stdin);
	freopen("summer.out","w",stdout); 
	scanf("%lld %lld",&n,&k);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);	
	int q;
	scanf("%lld",&q);
	while(q--) {
		int x,l,r,ans=0;
		scanf("%lld %lld %lld",&x,&l,&r);
		swap(a[x],a[x+1]);
		for(int i=l;i<=r;i++) ans+=solve(i);
		printf("%lld\n",ans);
	}
	return 0;
} 

/*
7 7
4 3 2 1 2 3 4
5
1 1 3
2 3 5
3 2 5
4 1 5
5 1 5
*/
